//
//  WLStatusRetweetView.swift
//  WLWeibo
//
//  Created by Devil on 16/8/13.
//  Copyright © 2016年 Wiliam. All rights reserved.
//

import UIKit
import SnapKit
class WLStatusRetweetView: UIView {

    var retweetViewBottomConstraint: Constraint?
    var statusViewModel: WLStatusViewModel?{
    
        didSet{
        
            contentLabel.text = statusViewModel?.statusModel?.retweeted_status?.text
            
            retweetViewBottomConstraint?.uninstall()
            if statusViewModel?.statusModel?.retweeted_status?.pic_urls?.count > 0 {
                pictureView.pictureInfos = statusViewModel?.statusModel?.retweeted_status?.pic_urls

                self.snp_makeConstraints(closure: { (make) in
                    retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
                })
                
                pictureView.hidden = false
            }else{
            
                self.snp_makeConstraints(closure: { (make) in
                    retweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(10).constraint
                })
                
                pictureView.hidden = true
            
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
    
        backgroundColor = RandomColor()
        addSubview(contentLabel)
        addSubview(pictureView)
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.leading.top.equalTo(10)
        }
        
        pictureView.snp_makeConstraints { (make) in
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
//            make.size.equalTo(CGSize(width: 100, height: 100))
            make.leading.equalTo((SCREENW - 250)/2)
        }
        
        self.snp_makeConstraints { (make) in
            retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
        }
    
    }
    
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(),textSize: 15,maxWidth: SCREENW - 20)
    private lazy var pictureView: WLStatusPictureView = WLStatusPictureView()

}
